package com.bdqn.zhang.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * <Description> <br>
 *
 * @author tao<br>
 * @version 1.0<br>
 * @taskId: <br>
 * @createDate 2019/10/15 14:29 <br>
 * @see com.bdqn.zhang.controller <br>
 */
@ControllerAdvice //@ControllerAdvice 该注解定义全局异常处理类
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class) //@ExceptionHandler 该注解声明异常处理方法
    public String defaultErrorHandler(HttpServletRequest req, Exception e, Model model) throws Exception {
        model.addAttribute("exception", e);  //异常内容(页面展示)
        model.addAttribute("url", req.getRequestURL()); //请求的url地址(页面展示)
        return "error";
    }
}
